package cn.amebius.avoice.controller;

import cn.amebius.avoice.pojo.users.Student;
import cn.amebius.avoice.service.StudentService;
import cn.amebius.avoice.util.CodeUtil;
import cn.amebius.avoice.util.MessageUtil;
import com.sun.xml.internal.xsom.XSUnionSimpleType;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author 阿伟
 * @Date 2022/10/14 20:15
 */

@Controller
public class TestController {

    @Autowired
    private StudentService studentService;

    @RequestMapping(value = "/api/test",method = RequestMethod.POST)
    @ResponseBody
    public Result testOne(Student student, String msg,HttpServletResponse response) throws IOException {
        Result result = new Result();
        boolean isLogin = studentService.studentLogin(student);
        boolean isExist = studentService.studentExist(student);
        if (isLogin) {
            result.setCode(CodeUtil.STUDENT_LOGIN_SUCCESS);
            result.setMsg(MessageUtil.STUDENT_LOGIN_SUCCESS);
        } else {
            if (isExist) {
                result.setCode(CodeUtil.STUDENT_LOGIN_FAIL_PASSWORD);
                result.setMsg(MessageUtil.STUDENT_LOGIN_FAIL_PASSWORD);
            } else {
                result.setCode(CodeUtil.STUDENT_LOGIN_FAIL_EXIST);
                result.setMsg(MessageUtil.STUDENT_LOGIN_FAIL_EXIST);
            }
        }
        return result;
    }


}
